package com.yuchen.ishop.web.app.buyer;

import com.yuchen.ishop.entity.*;
import com.yuchen.ishop.service.buyer.BuyerCommentRestClient;
import com.yuchen.ishop.service.goods.GoodsRestClient;
import com.yuchen.ishop.service.seller.SellerRestClient;
import com.yuchen.ishop.service.seller.ShopRestClient;
import com.yuchen.ishop.service.seller.XiaoerRestClient;
import com.yuchen.ishop.vo.CookieUserInfo;
import com.yuchen.ishop.web.BaseAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/my/buyer/comment")
public class BuyerCommentAction extends BaseAction {

    @Autowired
    private BuyerCommentRestClient buyerCommentRestClient;

    @Autowired
    private GoodsRestClient goodsRestClient;

    @RequestMapping(value = "index")
    public String index(HttpServletRequest request, ModelMap modelMap) {
        CookieUserInfo userInfo = cookie2UserInfo(request);
        String range = null;
        if("tab2".equals(request.getParameter("tab"))){
            range = "2";
        }else{
            range = "1";
        }
        List list = buyerCommentRestClient.getByBuyerId(userInfo.getId(), range);

        modelMap.addAttribute("list", list);
        modelMap.addAttribute("myMenu", "myComment");
        modelMap.addAttribute("range", range);
        return "my/buyer/myComment";
    }

    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public String delete(Long id, ModelMap modelMap) {
        buyerCommentRestClient.delete(id);
        return "redirect:/my/buyer/comment/index.htm";
    }
}
